package main

import (
	"fmt"
	"gorm-gen/models"
	"gorm-gen/query"
	"gorm.io/driver/mysql"
	"gorm.io/gen"
	"gorm.io/gorm"
)

func main() {
	g := gen.NewGenerator(gen.Config{
		OutPath:       "./query",                                 // gen代码的输出目录
		ModelPkgPath:  "models",                                  // 模型代码的输出目录
		Mode:          gen.WithDefaultQuery | gen.WithoutContext, // 启用默认查询和链式接口
		FieldNullable: true,                                      // 允许 NULL 的字段生成指针类型
	})

	dia := mysql.Open("root:database_Sugon123@tcp(10.2.106.54:3306)/dasapp_commhub?charset=utf8mb4&parseTime=True&loc=Local")
	db, err := gorm.Open(dia, &gorm.Config{})
	if err != nil {
		fmt.Println(err)
		return
	}
	g.UseDB(db)
	g.GenerateModel("tb_user_team") // 通过模型生成gorm模型
	//g.GenerateAllTable()          // 通过sql表生成gorm模型
	g.Execute() // 执行

	g.ApplyBasic(models.TbUserTeam{})

	g.Execute() // 执行

	query.SetDefault(db)

	user := models.TbUserTeam{
		TeamID:   "123456",
		TeamName: "测试团队",
		Status:   "1",
		Remark:   "备注信息",
		CreateBy: "1234567890",
	}
	err = query.TbUserTeam.Create(&user)
	fmt.Println(user, err)

	query.TbUserTeam.Save(&user)

}
